﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Gao.Poker.Domain
{
    public class ProductHelper : INotifyPropertyChanged
    {
        private Decimal _discount;
        private int _number = 1;
        private Decimal _total;

        public ProductHelper(Product product)
        {
            Product = product;
        }

        public Product Product { get; set; }

        public String BarCode { get { return Product.BarCode; } }

        public String ProductName { get { return Product.ProductName; } }
        /// <summary>
        /// 所需积分
        /// </summary>
        public Decimal PIntegral { get { return Product.PIntegral; } }
        /// <summary>
        /// 数量
        /// </summary>
        public int PNumber { get { return Product.PNumber; } }

        public Decimal Discount
        {
            get { return _discount; }
            set { _discount = value; OnPropertyChanged("Total"); }
        }
        /// <summary>
        /// 购买数量
        /// </summary>
        public int Number
        {
            get { return _number; }
            set
            {
                _number = value;
                OnPropertyChanged("Total");
            }
        }

        public Decimal Total
        {
            get
            {
                _total = (PIntegral - Discount) * Number;
                return _total;
            }
            set { _total = value; }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
